package com.gao.api.gate.quick.tt;

import io.netty.channel.Channel;
import io.netty.channel.pool.ChannelPoolHandler;
import io.netty.channel.pool.SimpleChannelPool;
import io.netty.util.AttributeKey;

/**
 * <p></p>
 *
 * @author gaoshuangwen
 * @since 2022/02/14 21:22
 */
public class IdleChannelPoolHandler implements ChannelPoolHandler {
    private static final AttributeKey<SimpleChannelPool> POOL_KEY =
            AttributeKey.newInstance("io.netty.channel.pool.SimpleChannelPool");
    @Override
    public void channelReleased(Channel ch) throws Exception {

    }

    @Override
    public void channelAcquired(Channel ch) throws Exception {
        SimpleChannelPool pool = ch.attr(POOL_KEY).get();
        if (pool instanceof IdleChannelPool) {
            ((IdleChannelPool) pool).update();
        }
    }

    @Override
    public void channelCreated(Channel ch) throws Exception {

    }
}
